package super1.laboratory;

/**
 * @author shkstart
 * @date 2022/5/10 - 21:02
 */
public class Account {
    private int id;//账号
    protected double balance;//余额
    private double annualInterestRate;//年利率

    public Account() {

    }


    public Account(int id,double balance,double annualInterestRate) {
        this.id = id;
        this.balance = balance;
        this.annualInterestRate = annualInterestRate;
    }

    public int getId() {
        return id;
    }

    public double getBalance() {
        return balance;
    }

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }


    public void setId(int id) {
        this.id = id;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }

//                得到每月利息
    public double getMonthlyInterest() {
        return annualInterestRate/12;
    }
//              取款
    public void withdraw(double amount) {
        if (amount > balance) {
            System.out.println("很抱歉,您的账户余额不足" + ",余额为:" + balance);
        }else {
            balance -= amount;
            System.out.println("您已成功取出" + amount + "您的余额还剩" + balance);
        }

    }
//              存款
    public void deposit(double amount) {
        if (amount <= 0) {
            System.out.println("很抱歉,您输入的数字有误");
        }else {
            balance += amount;
            System.out.println("您已成功存入" + amount + "您的余额还剩" + balance);

        }
        System.out.println("月利率为:" + getMonthlyInterest()*100 + "%");
    }
}
